package com.diyunapp.xilinapp.adapters;

import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.diyunapp.xilinapp.R;
import com.diyunapp.xilinapp.bean.AddEvaBean;
import com.diyunapp.xilinapp.utils.AbDateUtil;
import com.squareup.picasso.Picasso;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/8/18.
 */
public class AddEvaAdapter extends BaseAdapter implements View.OnClickListener {
    private List<AddEvaBean.DataBean> list;
    private Context context;

    public AddEvaAdapter(List<AddEvaBean.DataBean> list, Context context) {

        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return null == list ? 0 : list.size();
    }

    @Override
    public Object getItem(int position) {
        return null == list ? null : list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_add_eva, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        final ViewHolder viewHolder = holder;
        final AddEvaBean.DataBean bean = list.get(position);
//            final ReceiveBean.OrderGoodsBean currentdata = bean.get(position);
        viewHolder.oldEvaluateContent.setText(bean.getGeval_content());
        viewHolder.evaluationTime.setText(AbDateUtil.getStringByFormat(bean.getGeval_addtime()*1000,"yyyy-MM-dd"));
        String image =bean.getImage();
        Picasso.with(context)
                .load(image)
                .resize(200, 200)
                .centerCrop()
                .placeholder(R.drawable.list_default)
                .error(R.drawable.list_default)
                .into(viewHolder.goodsImage);
        viewHolder.addEvaluation.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                bean.setEva_content(s.toString());
            }
            @Override
            public void afterTextChanged(Editable s) {
            }
        });

        return convertView;
    }

    @Override
    public void onClick(View v) {

    }

    static class ViewHolder {
        @Bind(R.id.goods_image)
        ImageView goodsImage;
        @Bind(R.id.old_evaluate_content)
        TextView oldEvaluateContent;
        @Bind(R.id.evaluation_time)
        TextView evaluationTime;
        @Bind(R.id.add_evaluation)
        EditText addEvaluation;
        @Bind(R.id.shangchuan)
        ImageView shangchuan;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}